package com.alex.service.r.rentity;

import cn.hutool.core.util.StrUtil;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Data
@NoArgsConstructor
public class AuthorPairs {
    String firstAu;
    String secondAu;
    String zuHe;

    public AuthorPairs(String firstAu, String secondAu) {
        this.firstAu = firstAu.trim();
        this.secondAu = secondAu.trim();
        List<String> aulist = new ArrayList<>();
        aulist.add(firstAu.trim());
        aulist.add(secondAu.trim());
        Collections.sort(aulist);
        this.zuHe = StrUtil.join("|", aulist);
    }

    @Override
    public int hashCode() {
        return this.zuHe.hashCode();
    }


    @Override
    public boolean equals(Object obj) {
        AuthorPairs authorPairs = (AuthorPairs) obj;
        return this.getZuHe().equals(authorPairs.getZuHe());
    }
}
